package atguigu.demo3

import scala.math._

/**
  * Created by lzd on 2018/10/26.
  */
object demo2_2 {

  def fun(x: Double) = {
    if (x >= 0) sqrt(x)
    else throw new IllegalArgumentException("ill args error")

  }

  def main(args: Array[String]): Unit = {
    try {
      println(fun(4))
      println(fun(-4))
    } catch {
      case e: Exception => println(e)
    } finally {
      println("try catch end ...")
    }

    println("-------------------------------")
    noLazy()
    println("-------------------------------")
    lazyed()
  }


  def init(): String = {
    println("call init()")
    return "hello"
  }


  def noLazy() {
    //没有使用lazy修饰
    val property = init();
    println("after init()")
    println(property)
  }

  def lazyed() {
    //使用lazy修饰，遇到调用property后才执行init，否则就不执行了。
    lazy val property = init();
    println("after init()")
    println(property)
  }
}
